import java.util.ArrayList;
import java.util.List;


public class ClipboardHinstory
{
	private int indexOffset = 0;
	private List<String> list = new ArrayList<String>();

	public void add(String clipboardContents)
	{
		list.add(clipboardContents);
	}

	public String prev()
	{
		System.out.println("size: " + list.size() + " offset: " + indexOffset);
		String prev = null;
		if ( list.size() > 1 && (indexOffset + list.size() > 0) ) {
			int index = list.size() - 1; 
			index += --indexOffset;
			prev = list.get(index);
		} else if (list.size() > 0) {
			prev = list.get(list.size()-1);
		}
		return prev;
	}
	
	public String next()
	{
		System.out.println("size: " + list.size() + " offset: " + indexOffset);
		String next = null;
		if (list.size() > 0 && indexOffset < 0) {
			int index = list.size() - 1;
			index += ++indexOffset;
			next = list.get(index);
		} else if (list.size() > 0) {
			next = list.get(list.size()-1);
		}
		return next;
	}
}
